var moduleV = 20180517001;
layui.extend({
	conf: 'config.js?v=' + moduleV,
	admin: 'admin.js?v=' + moduleV,
	view : 'view.js?v=' + moduleV,
	msg : 'lib/msg.js?v=' + moduleV,
	ajax: 'lib/ajax.js?v=' + moduleV,
	utils: 'lib/utils.js?v=' + moduleV,
	tablePage : 'lib/tablePage.js?v=' + moduleV,
	sortMap : 'lib/sortMap.js?v=' + moduleV
}).define(['conf','element','admin','layer'], function(exports){
	var $ = layui.jquery;
	var element = layui.element;
	var conf = layui.conf;
	var admin = layui.admin;
	
	//监听导航点击
	element.on('nav(admin-side-nav)', function(elem){
		$(".layui-layout-body").removeClass("mini-menu");
		$("#admin-side-menu li a").off("mouseenter").off("mouseleave");
		//点击菜单是收起其他菜单
//		if(!$(elem).parent("dd")[0]){
//			$("#admin-side-menu .layui-nav-itemed").removeClass("layui-nav-itemed")
//			$(elem[0]).parent("li.layui-nav-item").addClass("layui-nav-itemed")
//		}
		layer.closeAll('tips');
		$("#sideMenuBar").removeClass("icon-menu-show").addClass("icon-menu-hide");
	});
	
	//收起和显示侧边栏
	$("#sideMenuBar").on("click", function(){
		$(".layui-layout-body").toggleClass("mini-menu")
		if($(".layui-layout-body").hasClass("mini-menu")){
			$("#admin-side-menu li a").on("mouseenter",function () {
	             layer.tips($(this).html(), this);
	        }).on("mouseleave",function () {
	             layer.closeAll('tips');
	        });
		}else{
			$("#admin-side-menu li a").off("mouseenter").off("mouseleave");
		}
		$(this).toggleClass("icon-menu-hide").toggleClass("icon-menu-show");
	})
	
	
	load = function(){
		var href = layui.router().href;
		target = admin.utils.getUrlPara("t", href);
		admin.redirect(href, utils.hexToString(target));
		admin.refreshLeftNav();
		window.onRefresh = null;
	};
	
	$("#mainRefresh").on("click", function(){
		window.onRefresh ?  window.onRefresh() : load();
	});
	$(window).on("hashchange", load);
	$(load);
	
	exports("main");
})